package org.example.flea_market_mvc.service.ratings.impl;

import org.example.flea_market_mvc.entity.Ratings;
import org.example.flea_market_mvc.mapper.RatingsMapper;
import org.example.flea_market_mvc.param.RatingParam;
import org.example.flea_market_mvc.service.ratings.RatingsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户评价服务实现类
 * 处理评价提交、卖家回复、评价查询等业务逻辑
 */
@Service
public class RatingsServiceImpl implements RatingsService {

    @Autowired
    private RatingsMapper ratingsMapper;

    @Override
    public int insert(RatingParam ratingParam) {
        Ratings rating = new Ratings();
        BeanUtils.copyProperties(ratingParam, rating);
        return ratingsMapper.insert(rating);
    }

    @Override
    public int deleteById(Integer id) {
        return ratingsMapper.deleteById(id);
    }

    @Override
    public int update(RatingParam ratingParam) {
        Ratings rating = new Ratings();
        BeanUtils.copyProperties(ratingParam, rating);
        return ratingsMapper.update(rating);
    }

    @Override
    public Ratings selectById(Integer id) {
        return ratingsMapper.selectById(id);
    }

    @Override
    public List<Ratings> selectAll() {
        return ratingsMapper.selectAll();
    }

    @Override
    public Double getUserAverageRating(Integer userId) {
        return ratingsMapper.getUserAverageRating(userId);
    }
}